/**
 * Contains {@link SwitchRecord}
 */
package logic.pathelements;

import java.net.Inet4Address;
import java.net.UnknownHostException;
import logic.connectors.Connector;

/**
 * Switch connector to other active path element macAddress correspondence
 * @author Alexey Akimov <frinatella@gmail.com>
 */
 public class RouterRecord extends Record {
     
    /**
     *  Network or node destination IPv4 address
     */
    Inet4Address destinaton;
    
    /**
     * Next network node to destinate {@link destinaton}
     */
    Inet4Address gateway;
    
    /**
     * This route record cost (may be hops count)
     */
    int metric;
    
    /**
     * Netmask for {@link destinaton}
     */
    Inet4Address netmask;
    
    /**
     * Constructor
     * @param connector connector by which this route starts
     * @param destination destination ipv4 adress
     * @param netmask netmask
     * @param gateway gateway ipv4 adress
     * @param metric this path record metric
     */
    public RouterRecord(Connector connector, Inet4Address destination, Inet4Address netmask, Inet4Address gateway, int metric) {
        super(connector);
        this.destinaton = destination;
        this.netmask = netmask;
        this.gateway = gateway;
        this.metric = metric;
    }
    
    /**
     * Constructor
     * @param connector connector by which this route starts
     * @param destination destination ipv4 adress
     * @param netmask netmask
     * @param gateway gateway ipv4 adress
     * @param metric this path record metric
     */
    public RouterRecord(Connector connector, String destination, String netmask, String gateway, int metric) throws UnknownHostException {
        super(connector);
        this.destinaton = (Inet4Address) Inet4Address.getByName(destination);
        this.netmask = (Inet4Address) Inet4Address.getByName(netmask);
        this.gateway = (Inet4Address) Inet4Address.getByName(gateway);
        this.metric = metric;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RouterRecord other = (RouterRecord) obj;
        if (this.connector == other.connector 
            && this.destinaton.equals(other.destinaton)
            && this.gateway.equals(other.gateway)
            && this.metric == other.metric
            && this.netmask.equals(other.netmask)) {
            return true;
        }
        return false;
    }
    
    /**
     * Getter
     * @return network or node destination IPv4 address
     */
    public Inet4Address getDestinaton() {
        return destinaton;
    }

    /**
     * Getter
     * @return next network node to destinate {@link getDestinaton}
     */
    public Inet4Address getGateway() {
        return gateway;
    }

    /**
     * Getter
     * @return this route record cost (may be hops count)
     */
    public int getMetric() {
        return metric;
    }

    /**
     * Getter
     * @return Netmask for {@link getDestinaton}
     */
    public Inet4Address getNetmask() {
        return netmask;
    }
    
}
